package edu.myown.node;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
//import java.io.Serializable;

public class RmiNodeStorageServer extends UnicastRemoteObject implements RmiNodeStorage{
      
		private NodeStorage nodeStorage;
	
		public RmiNodeStorageServer(NodeStorage nodeStorage) throws RemoteException {
			this.nodeStorage = nodeStorage;
		}

		public Node read() throws RemoteException{
			try {
				System.out.println("RmiNodeStorageServer: read.");
				return nodeStorage.read();
			}catch (NodeStorageException e) {
//				System.out.println("Node read error!" + e.getMessage());
//				e.printStackTrace();
				
				throw new RemoteException("2nd:Reading error ", e);
				
			} 
		}
		
		public void store(Node node)  throws RemoteException{
		
			try {
				System.out.println("RmiNodeStorageServer: store.");
				nodeStorage.store(node);
			}catch (NodeStorageException e) {
//				System.out.println("Node save error!" + e.getMessage());
//				e.printStackTrace();
				
				throw new RemoteException("Storing error", e);
				
			}
		}
}